package com.empire.module.sporttery.service.football500yazdetail;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500yazdetail.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500yazdetail.Football500YazDetailDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500yazdetail.Football500YazDetailMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 亚盘详情 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500YazDetailServiceImpl implements Football500YazDetailService {

    @Resource
    private Football500YazDetailMapper football500YazDetailMapper;

    @Override
    public Integer createFootball500YazDetail(Football500YazDetailSaveReqVO createReqVO) {
        // 插入
        Football500YazDetailDO football500YazDetail = BeanUtils.toBean(createReqVO, Football500YazDetailDO.class);
        football500YazDetailMapper.insert(football500YazDetail);
        // 返回
        return football500YazDetail.getId();
    }

    @Override
    public void updateFootball500YazDetail(Football500YazDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500YazDetailExists(updateReqVO.getId());
        // 更新
        Football500YazDetailDO updateObj = BeanUtils.toBean(updateReqVO, Football500YazDetailDO.class);
        football500YazDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500YazDetail(Integer id) {
        // 校验存在
        validateFootball500YazDetailExists(id);
        // 删除
        football500YazDetailMapper.deleteById(id);
    }

    private void validateFootball500YazDetailExists(Integer id) {
        if (football500YazDetailMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_YAZ_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public Football500YazDetailDO getFootball500YazDetail(Integer id) {
        return football500YazDetailMapper.selectById(id);
    }

    @Override
    public PageResult<Football500YazDetailDO> getFootball500YazDetailPage(Football500YazDetailPageReqVO pageReqVO) {
        return football500YazDetailMapper.selectPage(pageReqVO);
    }

}